package com.wlts.wzy.sys_shiro.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wlts.wzy.Result.Result;
import com.wlts.wzy.sys_shiro.entity.SysRole;
import com.wlts.wzy.sys_shiro.service.impl.SysRoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDateTime;


/**
 * <p>
 * 系统角色表 前端控制器
 * </p>
 *
 * @author wuzhiyong
 * @since 2019-03-27
 */
@ApiIgnore
@RestController
@RequestMapping("/sys-role")
public class SysRoleController {
    @Autowired
    private SysRoleServiceImpl sysRoleService;

    /**
     * 系统角色创建
     * @param sysRole
     * @return
     */
    @RequestMapping("buildsysRole")
    public Result builesysRole(@RequestBody SysRole sysRole){
        sysRole.setCreateDate(LocalDateTime.now());
        sysRole.setUpdateDate(LocalDateTime.now());
        SysRole sysRole1=sysRoleService.getOne(new QueryWrapper<SysRole>().eq("rolename",sysRole.getRolename()).eq("del_flag","0"));
        if(sysRole1==null){
            sysRoleService.save(sysRole);
            sysRole=sysRoleService.getOne(new QueryWrapper<SysRole>().eq("rolename",sysRole.getRolename()).eq("del_flag","0"));
              return Result.buildResult(sysRole.getId());
        }
        return new Result<>(500,"系统角色重复！");
    }
    //删除
    @RequestMapping("deletesysRole")
    public Result deletesysRole(@RequestBody SysRole sysRole) {
        sysRole.setUpdateDate(LocalDateTime.now());
        SysRole sysRole1 = sysRoleService.getById(sysRole.getId());
        if (sysRole1 != null) {
            sysRole1.setDelFlag("1");
            sysRoleService.updateById(sysRole1);
              return new Result<>();
        }
        return new Result<>(500,"删除失败！");
    }
    //修改
    @RequestMapping("changesysRole")
    public Result changesysRole(@RequestBody SysRole sysRole) {
        sysRole.setUpdateDate(LocalDateTime.now());
        SysRole sysRole1 = sysRoleService.getById(sysRole.getId());
        if (sysRole1 != null) {
            sysRoleService.updateById(sysRole);
              return new Result<>();
        }
        return new Result<>(500,"修改失败！");
    }
    //查询
    @RequestMapping("selectsysRole")
    public Result selectsysRole(@RequestBody SysRole sysRole) {
        sysRole.setUpdateDate(LocalDateTime.now());
        SysRole sysRole1 = sysRoleService.getById(sysRole.getId());
          return Result.buildResult(sysRole1);
    }




}
